<template>
  <div class="station-card">
    <!-- 自定义标题栏 -->
    <div class="card-header">
      <div class="card-title"> 3:包裹/托盘/分离/制箱 </div>
    </div>
    
    <!-- 数据区域：左侧为动态数据，右侧固定显示"是否成功" -->
    <div class="data-container">
      <!-- 左侧动态数据区域 - flex两端对齐布局 -->
      <div class="dynamic-data">
        <div class="data-item">
          <span class="label">任务编号</span>
          <span class="value">T2508210001</span>
        </div>
        <div class="data-item">
          <span class="label">面单号</span>
          <span class="value">T2508210001</span>
        </div>
        <div class="data-item">
          <span class="label">容器编号</span>
          <span class="value">P01</span>
        </div>
      </div>
      
      <!-- 右侧固定显示"是否成功" -->
      <div class="fixed-status">
        <div class="data-item status-item">
          <span class="label">是否成功</span>
          <span class="value" :class="successStatusClass">{{ successStatus }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed, ref } from 'vue';

// 接收父组件参数
const props = defineProps({
  data: { 
    type: Object, 
    default: () => ({
      title: '工位信息',
      sn: 'SN20230725001',
      waybill: 'SF232102909',
      order: 'T001211',
      traceCode: 'D001211',
      isSuccess: true,
      extraFields: [] // 可添加额外的动态字段
    })
  }
});

// 提取动态字段
const dynamicFields = ref([
  { label: '料箱号', value: props.data.sn },
  { label: '运单号', value: props.data.waybill },
  { label: '订单号', value: props.data.order },
  { label: '追溯码', value: props.data.traceCode },
  ...props.data.extraFields
]);

// 成功状态文本
const successStatus = computed(() => {
  return props.data.isSuccess ? 'OK' : 'NG';
});

// 成功状态样式
const successStatusClass = computed(() => {
  return props.data.isSuccess ? 'status-ok' : 'status-ng';
});
</script>

<style scoped>
.station-card {
  width: 100%;
  height: 100%;
  background: linear-gradient(145deg, #0a2a66, #082459);
  border: 1px solid rgba(100, 149, 237, 0.2);
  border-radius: 0.4vw;
  padding: 0.5vw;
  box-shadow: 0 0.2vw 1vw rgba(0, 10, 30, 0.3);
  color: #e6eefc;
  box-sizing: border-box;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px dashed rgba(100, 149, 237, 0.3);
}

.card-title {
 font-size: clamp(16px,1.1vw,18px);
  font-weight: 600;
  color: #4da6ff;
}

.data-container {
  padding-top: 10px;
  display: flex;
  gap: 1vw;
  height: calc(100% - 40px);
}

/* 左侧动态数据区域 - flex布局实现两端对齐 */
.dynamic-data {
  flex: 1;
  display: flex;
  flex-wrap: wrap; /* 允许换行 */
  align-content: flex-start; 
  gap: 0.8vw; /* 项目间距 */
  max-height: 100%;
  overflow-y: auto;
  padding-right: 0.2vw;
}

/* 每个数据项占据约一半宽度（减去间距） */
.data-item {
  flex: 1; /* 计算宽度，考虑间距 */
  display: flex;
  flex-direction: column;
  gap: 0.3vw;
  box-sizing: border-box;
}
/* 最后一行只有一个元素时左对齐 */
.dynamic-data::after {
  content: '';
  flex: 0 0 calc(50% - 0.4vw);
  visibility: hidden;
}

/* 滚动条样式 */
.dynamic-data::-webkit-scrollbar {
  width: 0.3vw;
}

.dynamic-data::-webkit-scrollbar-track {
  background: rgba(100, 149, 237, 0.1);
  border-radius: 0.2vw;
}

.dynamic-data::-webkit-scrollbar-thumb {
  background: rgba(100, 149, 237, 0.5);
  border-radius: 0.2vw;
}

.fixed-status {
  min-width: 120px;
  width: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 0.5vw;
  border-left: 1px dashed rgba(100, 149, 237, 0.3);
}

.label {
  font-size: 0.8vw;
  color: #8da5c8;
  opacity: 0.9;
}

.value {
  font-size: 1vw;
  font-weight: 500;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-item .value {
  font-size: 1.5vw;
  font-weight: bold;
}

.status-ok {
  color: #4cd964;
  text-shadow: 0 0 0.4vw rgba(76, 217, 100, 0.6);
}

.status-ng {
  color: #ff6b6b;
  text-shadow: 0 0 0.4vw rgba(255, 107, 107, 0.6);
}
</style>
